<template>
  <div class="register">
    <div class="header">
      <span class="btn fl" @click="goBack">返回</span>
    </div>
    <form class="form">
      <div class="form-item">
        <div class="label">用户名</div>
        <input type="text" v-model="userForm.userName">
      </div>
      <div class="form-item">
        <div class="label">密码</div>
        <input type="password" v-model="userForm.password">
      </div>
      <div class="form-item">
        <div class="label"></div>
        <button @click="onsubmit">注册</button>
      </div>
    </form>
  </div>
</template>

<script>
import { register } from '@/api/user'
export default {
  name: 'register',
  data () {
    return {
      userForm: {
        userName: '',
        password: ''
      }
    }
  },
  methods: {
    onsubmit () {
      register(this.userForm)
        .then(res => {
          console.log(res)
          alert('保存成功！')
        })
    },

    goBack() {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped lang="scss">
  .register {
    .form {
      .form-item {
        margin-top: 10px;
        .label {
          width: 100px;
          display: inline-block;
        }
      }
    }
  }
</style>
